package org.springframework;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;

import java.util.List;

public class ConversionServiceTest {

	Logger log = LoggerFactory.getLogger(ConversionServiceTest.class);

	@Test
	public void testConversionService() {
		DefaultConversionService service = new DefaultConversionService();
		String source = "123";
		boolean canConvert = service.canConvert(String.class, Integer.class);
		if (canConvert) {
			Integer result = service.convert(source, Integer.class);
			log.info("result: {}", result);
		}
	}

	@Test
	public void testConvertList(){
		String source = "100,12,23,54,56";
		ConversionService conversionService = new DefaultConversionService();
		if(conversionService.canConvert(String.class, List.class)){
			List target = conversionService.convert(source, List.class);
			log.info("The number is {}.", target);
		}
	}

	@Test
	public void testConvert() {
		//自定义类型转化器
	}
}
